package com.wanaofu.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

@Entity
@Table(name = "USER_INFO",uniqueConstraints ={@UniqueConstraint(columnNames={"u_code"})})
public class UserInfo extends AbstractBaseEntity implements Serializable{
	private static final long serialVersionUID = 7258246485618794078L;
	public UserInfo() {}
	public UserInfo(String code,String name) {
		this.code = code;
		this.name = name;
	}
	public UserInfo(String code,String name,String pd) {
		this(code,name);
		this.password = pd ;
	}
	
	@Column(name = "U_CODE", nullable=false, length = 20 )
	@NotNull(message="code must not be null or empty.")
	@Size(min=1,max=10)
	private String code;
	
	@Column(name = "U_NAME", nullable=false, length = 40 )
	@NotNull(message="name must not be null or empty.")
	@Size(min=1,max=20)
	private String name;
	
	@Column(name = "U_PASSWORD", nullable=false, length = 32 )
	@NotNull(message="password must not be null or empty.")
	@Size(min=1,max=32)
	private String password;
	
	@Override
	boolean businessEquals(Object p) {
		if (!(p instanceof UserInfo)) return false ;
		
		UserInfo cp = (UserInfo)p;
        if (this.code == null || cp.code == null) return false;
        
		return this.code.equalsIgnoreCase(((UserInfo)p).code);
	}
	
	/* ===================  get/set method ======================*/
	public String getCode() {
		return code;
	}
	public void setCode(String code) {
		this.code = code;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
}
